package cn.i5.remoteinvocationcontrol.core;

import cn.i5.remoteinvocationcontrol.annotation.RemoteInvocationControl;
import cn.i5.remoteinvocationcontrol.config.RemoteInvocationControlConfig;
import cn.i5.remoteinvocationcontrol.constant.ControlWay;

/**
 * 外观校验类
 *
 * @author mc0710
 */
public class RemoteInvocationControlFacade {

    private WhiteIpChecker whiteIpChecker;
    private ServicesNameChecker servicesNameChecker;

    /**
     * 无参构造
     */
    public RemoteInvocationControlFacade() {
        whiteIpChecker = new WhiteIpChecker();
        servicesNameChecker = new ServicesNameChecker();
    }

    /**
     * 校验
     */
    public void check(RemoteInvocationControl remoteInvocationControl, RemoteInvocationControlConfig remoteInvocationControlConfig) {
        // 得到控制方式
        ControlWay[] controlWays = remoteInvocationControl.controlWay();
        for (ControlWay way : controlWays) {
            if (ControlWay.WHITE_IP.equals(way)) {
                // 白名单验证
                whiteIpChecker.check(remoteInvocationControlConfig);
            }
            if (ControlWay.SERVICES_NAME.equals(way)) {
                servicesNameChecker.check(remoteInvocationControl, remoteInvocationControlConfig);
            }
        }
    }

}
